package www.reagnetbox.com.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;

import www.reagnetbox.com.R;

public class ImageUtil {

    public static void loadImage(Context context, String path, ImageView iv, boolean isAvatar, boolean isCircleCrop) {
        Transformation<Bitmap> crop = isCircleCrop ? new CircleCrop() : new CenterCrop();
        int errorPlaceholder = isAvatar ? R.mipmap.ic_avatar_default : R.mipmap.ic_image_error_2;

//        String url = ValidateUtil.isStringValid(path) ?
//                path.contains("/storage") ? path : (path.contains("http") ? path : getCompleteImageUrl(path, true)) : "";
        Glide.with(context)
                .load(path)
                .placeholder(R.mipmap.ic_image)
                .apply(RequestOptions.bitmapTransform(crop).error(errorPlaceholder))
                .into(iv);
    }
}
